/*
 * Copyright (c) 2011 Joe Kopena <tjkopena@gmail.com>
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
*/

package com.rocketshipgames.haxe;

import flash.geom.Rectangle;
import flash.display.BitmapData;
import flash.events.KeyboardEvent;

import com.rocketshipgames.haxe.Engine;

class Context {

  static public var screenWidth:Int;
  static public var screenHeight:Int;

  static public var buffer:BitmapData = null;
  static public var bufferRectangle:Rectangle;

  static public var elapsed:Int = 0;
  static public var time:Int = 0;

  static public var engine:Engine;

  //--------------------------------------------
  static private var _keyDown:Array<Bool> = new Array();
  static private var _keyTrack:Array<Bool> = new Array();

  //------------------------------------------------------------
  //------------------------------------------------------------
  inline static public function keyDown(code:Int):Bool
  {
    return _keyDown[code];
  }

  inline static public function keyPressed(code:Int):Bool
  {
    var res:Bool = _keyTrack[code];
    _keyTrack[code] = false;
    return res;
    // end function keyCheck
  }


  //------------------------------------------------------------
  //------------------------------------------------------------
  static public function onKeyDown(event:KeyboardEvent)
  {
    Context._keyTrack[event.keyCode] = !Context._keyDown[event.keyCode];
    Context._keyDown[event.keyCode] = true;
    // end function onKeyDown
  }

  static public function onKeyUp(event:KeyboardEvent)
  {
    Context._keyTrack[event.keyCode] = false;
    Context._keyDown[event.keyCode] = false;
    // end function onKeyUp
  }

  // end class Context
}
